//
//  BFShCommitOrderItemView.m
//  BeautyFood
//
//  Created by imac on 2020/4/28.
//  Copyright © 2020 stoneobs. All rights reserved.
//

#import "BFShCommitOrderItemView.h"
@interface BFShCommitOrderItemView()
@property(nonatomic, strong) UIImageView                     *icon_imageview;/**< <##> */
@property(nonatomic, strong) STLabel                     *titleLable;/**<  */
@property(nonatomic, strong) STLabel                     *priceLable;/**<  */
@property(nonatomic, strong) STLabel                     *noteLable;/**<  */
@property(nonatomic, strong) STLabel                     *desLable;/**<  */

@property(nonatomic, strong) STLabel                     *didpayLable;/**<  */
@end
@implementation BFShCommitOrderItemView

- (void)setModel:(BFShShopCarModel *)model{
    _model = model;
    [self stoneobs_ui_configSubView];
    __weak typeof(self) weakSelf =  self;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [TMUtils goto_good_detail_witdh_id:model.goods_id];
    }];
    [self addGestureRecognizer:tap];
    self.userInteractionEnabled = YES;
}
- (void)setDetailModel:(THGoodDetailModel *)detailModel{
    _detailModel = detailModel;
    [self stoneobs_ui_config_detail_view];

    __weak typeof(self) weakSelf =  self;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [TMUtils goto_good_detail_witdh_id:detailModel.g_id];
    }];
    [self addGestureRecognizer:tap];
    self.userInteractionEnabled = YES;
}
- (void)setGoodModel:(BFShOrderModelGoodsModel *)goodModel{
    _goodModel = goodModel;
    [self config_order_detail_view];

    __weak typeof(self) weakSelf =  self;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [TMUtils goto_good_detail_witdh_id:goodModel.goods_id];
    }];
    [self addGestureRecognizer:tap];
    self.userInteractionEnabled = YES;
}
#pragma mark --configSubView
- (void)stoneobs_ui_configSubView{
    [self removeAllSubviews];
    self.width = STONEOBS_UI_UISCREEN_WIDTH;

    
    UIImageView * stoneobs_ui_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 24, 80, 80)];
    stoneobs_ui_imageView.image =PLACE_HOLDER_IMAGE_1;
    [self addSubview:stoneobs_ui_imageView];
    [stoneobs_ui_imageView sd_setImageWithURL:_model.goods_img.mj_url];
    stoneobs_ui_imageView.left = 15;
    self.icon_imageview = stoneobs_ui_imageView;
    stoneobs_ui_imageView.layer.cornerRadius = 10;
    stoneobs_ui_imageView.clipsToBounds = YES;
    
    CGFloat maxwitdh = STONEOBS_UI_UISCREEN_WIDTH - 20 - stoneobs_ui_imageView.right;
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(self.icon_imageview.right+10, self.icon_imageview.top, maxwitdh, 20)
                                                                text:@"[可口可乐] 汽水 碳酸饮料"
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:15
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self addSubview:stoneobs_ui_label];
        self.titleLable = stoneobs_ui_label;
        stoneobs_ui_label.text = self.model.goods_name;
    });
    

    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(self.icon_imageview.right+10, 10, maxwitdh, 20)
                                                                text:@" （6 x 24瓶 x 300ml） "
                                                           textColor:STONEOBS_UI_SECEND_TEXT_COLOR
                                                                font:12
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self addSubview:stoneobs_ui_label];
        stoneobs_ui_label.text = self.model.goods_spec;
        stoneobs_ui_label.left = self.titleLable.left;
        stoneobs_ui_label.centerY = self.icon_imageview.centerY;
        self.noteLable = stoneobs_ui_label;
        stoneobs_ui_label.text = [NSString stringWithFormat:@"%@%@",_model.type_name,_model.goods_spec];
        [NSString stoneobs_fun_lableAutoAdjustheightWithLabel:stoneobs_ui_label];
    });
    
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(self.icon_imageview.right+10, 10, maxwitdh, 20)
                                                                text:@"¥123/箱"
                                                           textColor:WH_UICOLOR_FROM_RGBA(0xFF6955)
                                                                font:15
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self addSubview:stoneobs_ui_label];
        stoneobs_ui_label.left = self.titleLable.left;
        self.priceLable = stoneobs_ui_label;
        self.priceLable.top = self.noteLable.bottom + 15;
        
        
        self.priceLable.text = [NSString stringWithFormat:@"￥%0.2f",self.model.goods_price];
        
//        self.height = self.priceLable.bottom + 10;
    });
    

    
    CGFloat top = self.priceLable.bottom + 10;
    ({
        NSString * title = [NSString stringWithFormat:@"x%@",@(_model.num)];
        STButton * button = [self viewFormLeftTitle:@"购买数量" value:title];
        button.top = top;
        top = button.bottom;
        [self addSubview:button];
    });
    
//    ({
//        STButton * button = [self viewFormLeftTitle:@"配送方式" value:[NSString stringWithFormat:@"快递(邮费%@)",self.model.cus_countPostage]];
//        button.top = top;
//        top = button.bottom;
//        [self addSubview:button];
//    });
    
    ({
        NSString * money = [NSString stringWithFormat:@"￥%0.2f",_model.num * _model.goods_price + self.model.cus_countPostage.floatValue];
        STButton * button = [self viewFormLeftTitle:@"小计" value:money];
        button.top = top;
        top = button.bottom;
        [self addSubview:button];
        UILabel * lable = [button viewWithTag:10001];
        lable.textColor = FlatRed;
    });
    
    self.textView = [[STTools_TextView alloc] initWithFrame:CGRectMake(17, top, STONEOBS_UI_UISCREEN_WIDTH - 34, 49)];
    [self.textView stbw_setBorderWith:1 borderColor:STMC_UICOLOR_FROM_RGBA(0xF8F8F8) cornerRadius:0];
    [self addSubview:self.textView];
    self.textView.placeholder = @"输入备注";
    self.textView.label.left = 5;
    self.textView.label.top = 5;
    
    self.height = self.textView.bottom + 10;

}
- (void)stoneobs_ui_config_detail_view{
    [self removeAllSubviews];
    self.width = STONEOBS_UI_UISCREEN_WIDTH;

    UIImageView * stoneobs_ui_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 24, 80, 80)];
    stoneobs_ui_imageView.image =PLACE_HOLDER_IMAGE_1;
    [self addSubview:stoneobs_ui_imageView];
    [stoneobs_ui_imageView sd_setImageWithURL:self.detailModel.img.mj_url];
    stoneobs_ui_imageView.left = 15;
    self.icon_imageview = stoneobs_ui_imageView;
    stoneobs_ui_imageView.layer.cornerRadius = 10;
    stoneobs_ui_imageView.clipsToBounds = YES;
    
    CGFloat maxwitdh = STONEOBS_UI_UISCREEN_WIDTH - 20 - stoneobs_ui_imageView.right;
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(self.icon_imageview.right+10, self.icon_imageview.top, maxwitdh, 20)
                                                                text:@"[可口可乐] 汽水 碳酸饮料"
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:15
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self addSubview:stoneobs_ui_label];
        self.titleLable = stoneobs_ui_label;
        stoneobs_ui_label.text = self.detailModel.name;
    });
    

    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(self.icon_imageview.right+10, 10, maxwitdh, 20)
                                                                text:@" （6 x 24瓶 x 300ml） "
                                                           textColor:STONEOBS_UI_SECEND_TEXT_COLOR
                                                                font:12
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self addSubview:stoneobs_ui_label];
        stoneobs_ui_label.left = self.titleLable.left;
        stoneobs_ui_label.centerY = self.icon_imageview.centerY;
        self.noteLable = stoneobs_ui_label;
        stoneobs_ui_label.text = [NSString stringWithFormat:@"%@%@",self.detailModel.cus_type_selcted,self.detailModel.cus_selected_spec.name];
        [NSString stoneobs_fun_lableAutoAdjustheightWithLabel:stoneobs_ui_label];
    });
    
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(self.icon_imageview.right+10, 10, maxwitdh, 20)
                                                                text:@"¥123/箱"
                                                           textColor:WH_UICOLOR_FROM_RGBA(0xFF6955)
                                                                font:15
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self addSubview:stoneobs_ui_label];
        stoneobs_ui_label.left = self.titleLable.left;
        self.priceLable = stoneobs_ui_label;
        self.priceLable.top = self.noteLable.bottom+10;
        
        
        self.priceLable.text = [NSString stringWithFormat:@"￥%0.2f",self.detailModel.cus_selected_spec_price.floatValue];
        
    });
    

    
    CGFloat top = self.priceLable.bottom + 10;
    ({
        NSString * title = [NSString stringWithFormat:@"x%@",@(self.detailModel.cus_selected_spec.cus_num)];
        STButton * button = [self viewFormLeftTitle:@"购买数量" value:title];
        button.top = top;
        top = button.bottom;
        [self addSubview:button];
    });
    if (self.detailModel.cus_selected_spec.integral.intValue > 0) {
        NSString * title = [NSString stringWithFormat:@"%ld",self.detailModel.cus_selected_spec.cus_num * self.detailModel.cus_selected_spec.integral.intValue];
        STButton * button = [self viewFormLeftTitle:@"赠送积分" value:title];
        button.top = top;
        top = button.bottom;
        [self addSubview:button];
    }
    
    ({
        STButton * button = [self viewFormLeftTitle:@"配送方式" value:[NSString stringWithFormat:@"快递(邮费%@)",self.detailModel.cus_countPostage]];
        button.top = top;
        top = button.bottom;
        [self addSubview:button];
    });
    
    ({
        NSString * money = [NSString stringWithFormat:@"￥%0.2f",self.detailModel.cus_selected_spec.cus_num * self.detailModel.cus_selected_spec_price.floatValue+ self.detailModel.cus_countPostage.floatValue];
        STButton * button = [self viewFormLeftTitle:@"小计" value:money];
        button.top = top;
        top = button.bottom;
        [self addSubview:button];
        UILabel * lable = [button viewWithTag:10001];
        lable.textColor = FlatRed;
    });
    
    
    self.textView = [[STTools_TextView alloc] initWithFrame:CGRectMake(17, top, STONEOBS_UI_UISCREEN_WIDTH - 34, 49)];
    [self.textView stbw_setBorderWith:1 borderColor:STMC_UICOLOR_FROM_RGBA(0xF8F8F8) cornerRadius:0];
    [self addSubview:self.textView];
    self.textView.placeholder = @"输入备注";
    self.textView.label.left = 5;
    self.textView.label.top = 5;
    
    self.height = self.textView.bottom + 10;
}
- (void)config_order_detail_view{
    [self removeAllSubviews];
    self.width = STONEOBS_UI_UISCREEN_WIDTH;

    UIImageView * stoneobs_ui_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 24, 80, 80)];
    stoneobs_ui_imageView.image =PLACE_HOLDER_IMAGE_1;
    [self addSubview:stoneobs_ui_imageView];
    [stoneobs_ui_imageView sd_setImageWithURL:self.goodModel.goods_img.mj_url];
    stoneobs_ui_imageView.left = 15;
    self.icon_imageview = stoneobs_ui_imageView;
    stoneobs_ui_imageView.layer.cornerRadius = 10;
    stoneobs_ui_imageView.clipsToBounds = YES;
    
    CGFloat maxwitdh = STONEOBS_UI_UISCREEN_WIDTH - 20 - stoneobs_ui_imageView.right;
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(self.icon_imageview.right+10, self.icon_imageview.top, maxwitdh, 20)
                                                                text:@"[可口可乐] 汽水 碳酸饮料"
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:15
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self addSubview:stoneobs_ui_label];
        self.titleLable = stoneobs_ui_label;
        stoneobs_ui_label.text = self.goodModel.goods_name;
    });
    

    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(self.icon_imageview.right+10, 10, maxwitdh, 20)
                                                                text:@" （6 x 24瓶 x 300ml） "
                                                           textColor:STONEOBS_UI_SECEND_TEXT_COLOR
                                                                font:12
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self addSubview:stoneobs_ui_label];
        stoneobs_ui_label.left = self.titleLable.left;
        stoneobs_ui_label.centerY = self.icon_imageview.centerY;
        self.noteLable = stoneobs_ui_label;
        stoneobs_ui_label.text = [NSString stringWithFormat:@"%@%@",self.goodModel.type_name,self.goodModel.spec];
        [NSString stoneobs_fun_lableAutoAdjustheightWithLabel:stoneobs_ui_label];
    });
    
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(self.icon_imageview.right+10, 10, maxwitdh, 20)
                                                                text:@"¥123/箱"
                                                           textColor:WH_UICOLOR_FROM_RGBA(0xFF6955)
                                                                font:15
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self addSubview:stoneobs_ui_label];
        stoneobs_ui_label.left = self.titleLable.left;
        self.priceLable = stoneobs_ui_label;
        self.priceLable.top = self.noteLable.bottom + 10;
        
        
        self.priceLable.text = [NSString stringWithFormat:@"￥%0.2f",self.goodModel.price.floatValue];
        
    });
    

    
    CGFloat top = self.priceLable.bottom + 10;
    ({
        NSString * title = [NSString stringWithFormat:@"x%@",self.goodModel.num];
        STButton * button = [self viewFormLeftTitle:@"购买数量" value:title];
        button.top = top;
        top = button.bottom;
        [self addSubview:button];
    });
    
//    ({
//        NSString * title = [NSString stringWithFormat:@"快递 ￥%@",self.goodModel.postage];
//        STButton * button = [self viewFormLeftTitle:@"配送方式" value:title];
//        button.top = top;
//        top = button.bottom;
//        [self addSubview:button];
//        UILabel * lable = [button viewWithTag:10001];
//        lable.textColor = FlatRed;
//        lable.attributedText = [lable.text stoneobs_fun_st_convertAttributeStringWithKeyWord:@"快递" attributes:@{NSForegroundColorAttributeName:STONEOBS_UI_THIRD_TEXT_COLOR}];
//    });
    
    ({

        STButton * button = [self viewFormLeftTitle:@"订单备注" value:self.goodModel.remark];
        button.top = top;
        top = button.bottom;
        [self addSubview:button];
    });
    
    ({
        NSString * money = [NSString stringWithFormat:@"￥%0.2f",self.goodModel.total_price.floatValue];
        STButton * button = [self viewFormLeftTitle:@"实付" value:money];
        button.top = top;
        top = button.bottom;
        [self addSubview:button];
        UILabel * lable = [button viewWithTag:10001];
        lable.textColor = FlatRed;
        self.height = top + 10;
    });
    
    
}
- (STButton*)viewFormLeftTitle:(NSString*)leftTitle value:(NSString*)value{
    STButton * view  = [[STButton alloc] initWithFrame:CGRectMake(0, 0, STONEOBS_UI_UISCREEN_WIDTH, 35)
                                                 title:nil
                                            titleColor:nil
                                             titleFont:0
                                          cornerRadius:0
                                       backgroundColor:nil
                                       backgroundImage:nil
                                                 image:nil];
    
    STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(17, 0, 120, view.height)
                                                            text:leftTitle
                                                       textColor:UIColor.blackColor
                                                            font:12
                                                     isSizetoFit:NO
                                                   textAlignment:NSTextAlignmentLeft];
    stoneobs_ui_label.font = [UIFont fontWithName:STONEOBS_UI_FONT_CU_NAME size:12];
    [view addSubview:stoneobs_ui_label];
    
    
    STLabel * stoneobs_ui_s_label = [[STLabel alloc] initWithFrame:CGRectMake(stoneobs_ui_label.right, 0, STONEOBS_UI_UISCREEN_WIDTH -stoneobs_ui_label.right - 20 , view.height)
                                                              text:value
                                                         textColor:STONEOBS_UI_THIRD_TEXT_COLOR
                                                              font:12
                                                       isSizetoFit:NO
                                                     textAlignment:NSTextAlignmentRight];
    [view addSubview:stoneobs_ui_s_label];
    [NSString stoneobs_fun_lableAutoAdjustheightWithLabel:stoneobs_ui_s_label];
    if (stoneobs_ui_s_label.height < view.height) {
        stoneobs_ui_s_label.height = view.height;
    }else{
        view.height = stoneobs_ui_s_label.height + 20;
    }
    stoneobs_ui_label.centerY = view.height/2;
    stoneobs_ui_s_label.centerY = view.height/2;
    stoneobs_ui_s_label.tag = 10001;

    __weak typeof(self) weakSelf =  self;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
  
    }];
    view.userInteractionEnabled = YES;
    [view addGestureRecognizer:tap];
    return view;
    
}
@end
